package bkone;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class deleteyhyh
 */
@WebServlet("/deleteyhyh")
public class deleteyhyh extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final String JDBC_URL = "jdbc:mysql://localhost:3309/blog?useUnicode=true&characterEncoding=utf8";
	private static final String DB_USER = "root";
	private static final String DB_PWD = "ZLWL";
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public deleteyhyh() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: deleteyhyh").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
		String deleteyhyhname = request.getParameter("deleteyhyhname");
		System.out.println("deleteyhyhname:" + deleteyhyhname);
		try {
		    Class.forName("com.mysql.jdbc.Driver").newInstance();
	    } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
		    e.printStackTrace();
	    }
	    Connection cont5 = null;
	    PreparedStatement prestn5 = null;
	    try {
	    	cont5 = DriverManager.getConnection(JDBC_URL, DB_USER, DB_PWD);
		    String scyhyh = "delete from user_zc where id = ?";
		    prestn5 = cont5.prepareStatement(scyhyh);
		    prestn5.setString(1, deleteyhyhname);
		    if(!deleteyhyhname.equals("")){
		    	prestn5.executeUpdate();
			}
		    prestn5.close();
		    cont5.close();
            response.sendRedirect("/admin_usergl.jsp");
	    } catch (SQLException e) {
		    e.printStackTrace();
	    }
	}

}
